/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Ali Subhani
 */
// importing required packages
import javax.swing.*;
import java.awt.*;
// extending class from JPanel
public class MyPanel extends JPanel {
// overriding paintComponent method
public void paintComponent(Graphics g){
// erasing behaviour - this will clear all the
// previous painting
super.paintComponent(g);
// Down casting Graphics object to Graphics2D
Graphics2D g2 = (Graphics2D)g;
// drawing rectanle
g2.drawRect(20,20,20,20);
// changing the color to blue
g2.setColor(Color.pink);
// drawing filled oval with color i.e. blue
g2.fillOval(50,50,20,20);
// drawing string
g2.drawString("Hello World", 120, 50);
}// end paintComponent
// method drawJava
public void drawJava(Graphics2D g2) {
// generate first number randomly. The panel width is 1000
int x = (int) (Math.random() * 1000);
// generate second number randomly. The panel height is 700
int y = (int) (Math.random() * 700);
// draw String on these randomly selected numbers
g2.drawString("I am student", x, y);
}

} // end Test class

